package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.OrderChannel;
import com.ruoyi.system.service.IOrderChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单渠道Controller
 *
 * @author hjf
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/hmk/channel")
public class OrderChannelController extends BaseController {
    @Autowired
    private IOrderChannelService orderChannelService;

    /**
     * 查询订单渠道列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderChannel orderChannel) {
        startPage();
        List<OrderChannel> list = orderChannelService.selectOrderChannelList(orderChannel);
        return getDataTable(list);
    }

    /**
     * 导出订单渠道列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:export')")
    //@Log(title = "订单渠道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderChannel orderChannel) {
        List<OrderChannel> list = orderChannelService.selectOrderChannelList(orderChannel);
        ExcelUtil<OrderChannel> util = new ExcelUtil<OrderChannel>(OrderChannel.class);
        util.exportExcel(response, list, "订单渠道数据");
    }

    /**
     * 获取订单渠道详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(orderChannelService.selectOrderChannelById(id));
    }

    /**
     * 新增订单渠道
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:add')")
    //@Log(title = "订单渠道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderChannel orderChannel) {
        return toAjax(orderChannelService.insertOrderChannel(orderChannel));
    }

    /**
     * 修改订单渠道
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:edit')")
    //@Log(title = "订单渠道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderChannel orderChannel) {
        return toAjax(orderChannelService.updateOrderChannel(orderChannel));
    }

    /**
     * 删除订单渠道
     */
    @PreAuthorize("@ss.hasPermi('hmk:channel:remove')")
    //@Log(title = "订单渠道", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderChannelService.deleteOrderChannelByIds(ids));
    }
}
